package com.wh.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wh.system.dao.PermissionDao;
import com.wh.system.dao.RolePermissionDao;
import com.wh.system.dto.RolePermissionDto;
import com.wh.system.pojo.Permission;
import com.wh.system.pojo.RolePermission;
import com.wh.system.service.IRolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class RolePermissionServiceimpl implements IRolePermissionService {

    @Autowired
    private RolePermissionDao rolePermissionDao;
    @Override
    public void add(RolePermission permission) {
        rolePermissionDao.insert(permission);
    }

    @Override
    public void del(Long id) {
        rolePermissionDao.deleteById(id);
    }

    @Override
    public void upd(RolePermission permission) {
        rolePermissionDao.updateById(permission);
    }

    @Override
    public List<RolePermission> findAll() {
        return rolePermissionDao.selectList(null);
    }

    @Override
    public RolePermission findById(Long id) {
        return rolePermissionDao.selectById(id);
    }
    @Override
    public IPage<RolePermission> findByPage(RolePermissionDto rolePermissionDto){
        //1.创建查询条件
        QueryWrapper<RolePermission> qw = new QueryWrapper<>();
        //qw.like("xxx",rolePermissionDto.getXxx());
        //qw.or();
        //qw.like("xxx",rolePermissionDto.getXxx());
        //2.组件分页数据
        IPage<RolePermission> page = new Page<>(rolePermissionDto.getCurrentPage(), rolePermissionDto.getPageSize());
        page.setRecords(rolePermissionDao.findByPage(page,qw));
        page.setTotal(rolePermissionDao.selectCount(qw));
        //3.返回
        return page;
    }

    @Override
    public List<Long> findpress(Long id) {
        return rolePermissionDao.findPermissionIdByRoleId(id);
    }

    @Override
    public void patchDel(List<Long> ids) {
        rolePermissionDao.deleteBatchIds(ids);
    }

}
